package com.example.lcode.backtrack;

import java.util.ArrayList;
import java.util.List;

public class Question78 {

    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        int startIndex = 0;
        List<Integer> subRes = new ArrayList<>();
        subsets(nums, nums.length, res, subRes, startIndex);
        return res;
    }

    private void subsets(int[] nums, int length, List<List<Integer>> res, List<Integer> subRes, int startIndex) {
        if (subRes.size() <=  length) {
            res.add(new ArrayList<>(subRes));
        } else {
            return;
        }
        for (int i = startIndex; i < nums.length; i++) {
            subRes.add(nums[i]);
            subsets(nums, length, res, subRes, i + 1);
            subRes.remove(subRes.size() - 1);
        }
    }

    public static void main(String[] args) {
        Question78 question78 = new Question78();
        int []arr = {0};
        List<List<Integer>> subsets = question78.subsets(arr);
        System.out.println(subsets);
    }

}
